home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Graphics / Gnuplot / Source / term / epson.trm < prev    next >
Encoding:
Text File  |  1993-03-02  |  11.4 KB  |  497 lines

  1. /*
  2.  * $Id: epson.trm 3.38.2.42 1993/01/07 17:23:59 woo Exp woo $
  3.  *
  4.  */
  5.  
  6. /* GNUPLOT - epson.trm */
  7. /*
  8.  * Copyright (C) 1990 - 1993   
  9.  *
  10.  * Permission to use, copy, and distribute this software and its
  11.  * documentation for any purpose with or without fee is hereby granted, 
  12.  * provided that the above copyright notice appear in all copies and 
  13.  * that both that copyright notice and this permission notice appear 
  14.  * in supporting documentation.
  15.  *
  16.  * Permission to modify the software is granted, but not the right to
  17.  * distribute the modified code.  Modifications are to be distributed 
  18.  * as patches to released version.
  19.  *  
  20.  * This software  is provided "as is" without express or implied warranty.
  21.  * 
  22.  * This file is included by ../term.c.
  23.  *
  24.  * This terminal driver supports:
  25.  *  epson_lx800, nec_cp6, starc,
  26.  *  epson_60dpi, tandy_60dpi
  27.  *
  28.  * AUTHORS
  29.  *  Russell Lang
  30.  *  William Wilson
  31.  *
  32.  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
  33.  * 
  34.  */
  35.  
  36. /* The following epson lx800 driver uses generic bit mapped graphics
  37.    routines to build up a bit map in memory. */
  38. /* by Russell Lang, rjl@monu1.cc.monash.edu.au */
  39. /* On PC, print using 'copy file /b lpt1:', do NOT use 'print' */
  40. /* EPSON_init changes outfile to binary mode on PC's */
  41.  
  42. #ifdef EPSONP
  43.  
  44. #define EPSONXMAX    512 
  45. #define EPSONYMAX    384
  46.  
  47. #define EPSONXLAST (EPSONXMAX - 1)
  48. #define EPSONYLAST (EPSONYMAX - 1)
  49.  
  50. #define EPSONVCHAR        FNT5X9_VCHAR      
  51. #define EPSONHCHAR        FNT5X9_HCHAR        
  52. #define EPSONVTIC        6
  53. #define EPSONHTIC        6
  54.  
  55. EPSONinit()
  56. {
  57. #ifdef REOPEN_BINARY
  58.     reopen_binary();
  59. #endif
  60. }
  61.  
  62.  
  63. EPSONgraphics()
  64. {
  65.     b_charsize(FNT5X9);
  66.     b_makebitmap((unsigned int)(EPSONXMAX*xsize),
  67.                  (unsigned int)(EPSONYMAX*ysize),1);
  68. }
  69.  
  70.  
  71. EPSONtext()
  72. {
  73.     epson_dump();
  74.     b_freebitmap();
  75. }
  76.  
  77.  
  78. #define EPSONlinetype b_setlinetype
  79. #define EPSONmove b_move
  80. #define EPSONvector b_vector
  81. #define EPSONput_text b_put_text
  82. #define EPSON_text_angle b_text_angle
  83.  
  84. EPSONreset()
  85. {
  86. #ifdef vms
  87.     fflush_binary();
  88. #endif
  89. }
  90.  
  91.  
  92. /* output file must be binary mode for epson_dump */
  93. epson_dump()
  94. {
  95.   register unsigned int x;
  96.   int j;
  97.     for (j=(b_ysize/8)-1; j>=0; j--) {
  98.         /* select plotter graphics mode (square pixels) */
  99.         fprintf(outfile,"\033J\030");    /* line feed 8/72" = 8 dots */
  100.         fprintf(outfile,"\r\033*\005");
  101.         (void) fputc((char)(b_xsize%256),outfile);
  102.         (void) fputc((char)(b_xsize/256),outfile);
  103.         for (x=0; x<b_xsize; x++) {
  104.             (void) fputc( (char)(*((*b_p)[j]+x)), outfile );
  105.         }
  106.     }
  107. #ifdef PC
  108.     fprintf(stderr,"Print using: COPY /B\n");
  109. #endif
  110. }
  111.  
  112. #endif /* EPSONP */
  113.  
  114.  
  115. /* The following NEC CP6 Pinwriter driver uses generic bit mapped graphics
  116.    routines to build up a bit map in memory. */
  117. /* by Russell Lang, rjl@monu1.cc.monash.edu.au */
  118. /* On PC, print using 'copy file /b lpt1:', do NOT use 'print' */
  119. /* NECinit changes outfile to binary mode for PC's */
  120.  
  121. /* Add a Monochrome NEC printer (for faster speed and line types) jdc */
  122.  
  123. #ifdef NEC
  124.  
  125. #define NECXMAX    400 
  126. #define NECYMAX    320
  127.  
  128. #define NECXLAST (NECXMAX - 1)
  129. #define NECYLAST (NECYMAX - 1)
  130.  
  131. #define NECVCHAR        FNT5X9_VCHAR      
  132. #define NECHCHAR        FNT5X9_HCHAR        
  133. #define NECVTIC        6
  134. #define NECHTIC        6
  135.  
  136. /* plane 0=black, 1=cyan(blue), 2=magenta(red), 3=yellow */
  137. static unsigned int neccolor[] = {1,8,4,2,10,12,6,14};
  138. static unsigned int necpcolor[]= {0,2,1,4};
  139.  
  140. static int NECmode;
  141.  
  142. NECoptions()
  143. {
  144.     if( END_OF_COMMAND ) {
  145.         strcpy(term_options,"monochrome");
  146.         NECmode='m';
  147.     } else
  148.     if( almost_equals(c_token,"m$onochrome") ) {
  149.         c_token++;
  150.         strcpy(term_options,"monochrome");
  151.         NECmode='m';
  152.     } else
  153.     if( almost_equals(c_token,"c$olor") ) {
  154.         c_token++;
  155.         strcpy(term_options,"color");
  156.         NECmode='c';
  157.     } else
  158.     if( almost_equals(c_token,"d$raft") ) {
  159.         c_token++;
  160.         strcpy(term_options,"draft");
  161.         NECmode='d';
  162.     } else {
  163.     /* error, but since the terminal is already set, default to mono */
  164.         strcpy(term_options,"monochrome");
  165.         NECmode='m';
  166.         int_error("modes: color, monochrome, draft",c_token);
  167.     }
  168. }
  169.  
  170. NECinit()
  171. {
  172. #ifdef REOPEN_BINARY
  173.     reopen_binary();
  174. #endif
  175. }
  176.  
  177. NECgraphics()
  178. {
  179.     b_charsize(FNT5X9);
  180.     b_makebitmap((unsigned int)(NECXMAX*xsize),
  181.              (unsigned int)(NECYMAX*ysize),(NECmode=='c' ? 4 : 1));
  182. }
  183.  
  184. NECtext()
  185. {
  186.     if( NECmode=='d' ) {
  187.         nec_draft_dump();
  188.     } else {
  189.     nec_dump();
  190.     }
  191.     b_freebitmap();
  192. }
  193.  
  194. NEClinetype(linetype)
  195. int linetype;
  196. {
  197.     if( NECmode=='c' ) {
  198.     if (linetype>=6)
  199.         linetype %= 6;
  200.     b_setvalue(neccolor[linetype+2]);
  201.     } else {
  202.         b_setlinetype(linetype);
  203.     }
  204. }
  205.  
  206. #define NECmove b_move
  207. #define NECvector b_vector
  208. #define NECput_text b_put_text
  209. #define NEC_text_angle b_text_angle
  210.  
  211.     
  212. NECreset()
  213. {
  214. #ifdef vms
  215.     fflush_binary();
  216. #endif
  217. }
  218.  
  219.  
  220. /* output file must be binary mode for nec_dump */
  221. nec_dump()
  222. {
  223. unsigned int x;
  224. unsigned int plane,offset;
  225. int j;
  226. unsigned int column8;
  227. unsigned long column24;
  228. char column3, column2, column1;
  229.     fprintf(outfile,"\033P\033l\005");  /* 10cpi, left margin 5 char */
  230.     for (j=(b_ysize/8)-1;j>=0;j--) {
  231.             fprintf(outfile,"\033J\030");  /* 24/180" line feed */
  232.             for (plane=0; plane<b_planes; plane++) {
  233.                 offset=plane*b_psize;
  234.                 if (b_planes>1) {
  235.                     /* select colour for plane */
  236.                     fprintf(outfile,"\033r");
  237.                     (void) fputc((char)necpcolor[plane],outfile);
  238.                 }
  239.                 /* select plotter graphics mode (square pixels) */
  240.                 fprintf(outfile,"\r\033*\047");
  241.                 (void) fputc((char)((b_xsize*3)%256),outfile);
  242.                 (void) fputc((char)((b_xsize*3)/256),outfile);
  243.                 for (x=0; x<b_xsize; x++) {
  244.                     column8= (unsigned int)(*((*b_p)[j+offset]+x));
  245.                     column24=0;
  246.                     if (column8&0x01) column24|=(long)0x000007;
  247.                     if (column8&0x02) column24|=(long)0x000038;
  248.                     if (column8&0x04) column24|=(long)0x0001c0;
  249.                     if (column8&0x08) column24|=(long)0x000e00;
  250.                     if (column8&0x10) column24|=(long)0x007000;
  251.                     if (column8&0x20) column24|=(long)0x038000;
  252.                     if (column8&0x40) column24|=(long)0x1c0000;
  253.                     if (column8&0x80) column24|=(long)0xe00000;
  254.                     column1 = (char) ( column24      & (long)0xff);
  255.                     column2 = (char) ((column24>>8)  & (long)0xff);
  256.                     column3 = (char) ((column24>>16) & (long)0xff);
  257.                     (void) fputc(column3,outfile);
  258.                     (void) fputc(column2,outfile);
  259.                     (void) fputc(column1,outfile);
  260.                     (void) fputc(column3,outfile);
  261.                     (void) fputc(column2,outfile);
  262.                     (void) fputc(column1,outfile);
  263.                     (void) fputc(column3,outfile);
  264.                     (void) fputc(column2,outfile);
  265.                     (void) fputc(column1,outfile);
  266.                 }
  267.             }
  268.     }
  269.     fprintf(outfile,"\r\033l");
  270.     (void) fputc('\0',outfile);                /* set left margin to 0 */
  271.     if (b_planes > 1) {
  272.         fprintf(outfile,"\033r");
  273.         (void) fputc('\0',outfile);                /* set color to black */
  274.     }
  275. #ifdef PC
  276.     fprintf(stderr,"Print using: COPY /B\n");
  277. #endif
  278. #ifdef vms
  279.     fflush_binary();
  280. #endif
  281. }
  282.  
  283. /* output file must be binary mode for nec_dump */
  284. nec_draft_dump()
  285. {
  286. unsigned int x;
  287. unsigned int plane,offset;
  288. int j;
  289.     fprintf(outfile,"\033P\033l\005\r");  /* 10cpi, left margin 5 char */
  290.     for (j=(b_ysize/8)-1;j>=0;j--) {
  291.             fprintf(outfile,"\033J\030");  /* 24/180" line feed */
  292.             for (plane=0; plane<b_planes; plane++) {
  293.                 offset=plane*b_psize;
  294.                 if (b_planes>1) {
  295.                     /* select colour for plane */
  296.                     fprintf(outfile,"\033r");
  297.                     (void) fputc((char)necpcolor[plane],outfile);
  298.                 }
  299.                 /* select plotter graphics mode (square pixels) */
  300.                 fprintf(outfile,"\r\033*");
  301.                 (void) fputc('\0',outfile);
  302.                 (void) fputc((char)(b_xsize%256),outfile);
  303.                 (void) fputc((char)(b_xsize/256),outfile);
  304.                 for (x=0; x<b_xsize; x++) {
  305.                     (void) fputc( (char)(*((*b_p)[j+offset]+x)), outfile );
  306.                 }
  307.             }
  308.     }
  309.     fprintf(outfile,"\r\033l");
  310.     (void) fputc('\0',outfile);                /* set left margin to 0 */
  311.     if (b_planes > 1) {
  312.         fprintf(outfile,"\033r");
  313.         (void) fputc('\0',outfile);                /* set color to black */
  314.     }
  315. #ifdef PC
  316.     fprintf(stderr,"Print using: COPY /B\n");
  317. #endif
  318. }
  319.  
  320. #endif /* NEC */
  321.  
  322. #ifdef STARC
  323. /* The following Star color driver uses generic bit mapped graphics
  324.    routines to build up a bit map in memory. */
  325. /* Star Color changes made by William Wilson, wew@naucse.cse.nau.edu */
  326. /* On PC, print using 'copy file /b lpt1:', do NOT use 'print' */
  327. /* STARC_init changes outfile to binary mode on PC's */
  328.  
  329. #define STARCXMAX    512 
  330. #define STARCYMAX    384
  331.  
  332. #define STARCXLAST (STARCXMAX - 1)
  333. #define STARCYLAST (STARCYMAX - 1)
  334.  
  335. #define STARCVCHAR        FNT5X9_VCHAR      
  336. #define STARCHCHAR        FNT5X9_HCHAR        
  337. #define STARCVTIC        6
  338. #define STARCHTIC        6
  339.  
  340. /* plane 0=black, 1=cyan(blue), 2=magenta(red), 3=yellow */
  341. static unsigned int STARCcolor[] = {1,8,4,2,10,12,6,14};
  342. static unsigned int STARCpcolor[]= {0,2,1,4};
  343.  
  344. STARCinit()
  345. {
  346. #ifdef REOPEN_BINARY
  347.     reopen_binary();
  348. #endif
  349. }
  350.  
  351.  
  352. STARCgraphics()
  353. {
  354.     b_charsize(FNT5X9);
  355.     b_makebitmap((unsigned int)(STARCXMAX*xsize),
  356.                  (unsigned int)(STARCYMAX*ysize),4);
  357. }
  358.  
  359.  
  360. STARCtext()
  361. {
  362.     STARC_dump();
  363.     b_freebitmap();
  364. }
  365.  
  366. STARClinetype(linetype)
  367. int linetype;
  368. {
  369.     if (linetype>=6)
  370.         linetype %= 6;
  371.     b_setvalue(STARCcolor[linetype+2]);
  372. }
  373.  
  374.  
  375. #define STARCmove b_move
  376. #define STARCvector b_vector
  377. #define STARCput_text b_put_text
  378. #define STARC_text_angle b_text_angle
  379.  
  380. STARCreset()
  381. {
  382. #ifdef vms
  383.     fflush_binary();
  384. #endif
  385. }
  386.  
  387.  
  388. /* output file must be binary mode for STARC_dump */
  389. STARC_dump()
  390. {
  391. unsigned int x;
  392. unsigned int plane,offset;
  393. int j;
  394.     for (j=(b_ysize/8)-1;j>=0;j--) {
  395.         fprintf(outfile,"\033J\030");    /* line feed 8/72" = 8 dots */
  396.         for (plane=0; plane<b_planes; plane++) {
  397.             offset=plane*b_psize;
  398.             if (b_planes>1) {
  399.                 /* select colour for plane */
  400.                 fprintf(outfile,"\033r");
  401.                 (void) fputc((char)STARCpcolor[plane],outfile);
  402.             }
  403.             /* select plotter graphics mode (square pixels) */
  404.             fprintf(outfile,"\r\033*\005");
  405.             (void) fputc((char)(b_xsize%256),outfile);
  406.             (void) fputc((char)(b_xsize/256),outfile);
  407.             for (x=0; x<b_xsize; x++) {
  408.                 (void) fputc( (char)(*((*b_p)[j+offset]+x)), outfile );
  409.             }
  410.         }
  411.     }
  412.     if (b_planes > 1) {
  413.         fprintf(outfile,"\033r");
  414.         (void) fputc('\0',outfile);                /* set color to black */
  415.     }
  416. #ifdef PC
  417.     fprintf(stderr,"Print using: COPY /B\n");
  418. #endif
  419. }
  420.  
  421. #endif /* STARC */
  422.  
  423.  
  424. #ifdef EPS60
  425.  
  426. /* make the total dimensions 8 inches by 5 inches */
  427. #define EPS60XMAX    480
  428. #define EPS60YMAX    360
  429.  
  430. #define EPS60XLAST (EPS60XMAX - 1)
  431. #define EPS60YLAST (EPS60YMAX - 1)
  432.  
  433. EPS60graphics()
  434. {
  435.     b_charsize(FNT5X9);
  436.     b_makebitmap((unsigned int)(EPS60XMAX*xsize),
  437.                  (unsigned int)(EPS60YMAX*ysize),1);
  438. }
  439.  
  440.  
  441. EPS60text()
  442. {
  443.     eps60_dump();
  444.     b_freebitmap();
  445. }
  446.  
  447.  
  448.  
  449. /* output file must be binary mode for eps60_dump */
  450. eps60_dump()
  451. {
  452.   register unsigned int x;
  453.   int j;
  454.     fprintf(outfile,"\033%c\030",'3'); /* set line spacing 24/216" = 8 dots */
  455.     for (j=(b_ysize/8)-1; j>=0; j--) {
  456.         /* select printer graphics mode 'K' */
  457.         fprintf(outfile,"\r\n\033K");
  458.         (void) fputc((char)(b_xsize%256),outfile);
  459.         (void) fputc((char)(b_xsize/256),outfile);
  460.         for (x=0; x<b_xsize; x++) {
  461.             (void) fputc( (char)(*((*b_p)[j]+x)), outfile );
  462.         }
  463.     }
  464.     fprintf(outfile,"\033%c\044\r\n",'3'); /* set line spacing 36/216" = 1/6" */
  465. #ifdef PC
  466.     fprintf(stderr,"Print using: COPY /B\n");
  467. #endif
  468. }
  469.  
  470. #endif /* EPS60 */
  471.  
  472. #ifdef TANDY60
  473.  
  474. /* The only difference between TANDY60 and EPS60 is the inclusion
  475.    of codes to swap the Tandy printer into IBM mode and back
  476.    into Tandy mode.  For a Tandy already in IBM mode, use EPS60. */
  477.  
  478.  
  479. TANDY60text()
  480. {
  481. #ifdef PC
  482.     fprintf(stderr, "Inserting Tandy/IBM mode conversion codes\n");
  483. #endif
  484.     /* Switch to IBM mode, and leave 3 inches above the plot so as
  485.        to get rough vertical centring on the page.  Perform the
  486.        centring by setting 1" line feeds and issuing 3 of them. */
  487.     fprintf(outfile, "\033!\033%c%c\n\n\n", '3',216);
  488.     eps60_dump();
  489.     b_freebitmap();
  490.     /* A form feed must be sent before switching back to Tandy mode,
  491.        or else the form setting will be messed up. */
  492.     fprintf(outfile, "\f\033!");
  493. }
  494.  
  495.  
  496. #endif  /* TANDY60 */
  497.